home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / sana2perror.c < prev    next >
C/C++ Source or Header  |  1994-03-24  |  3KB  |  94 lines

  1. RCS_ID_C="$Id: sana2perror.c,v 1.5 1994/03/24 17:04:36 jraja Exp $";
  2. /*
  3.  * sana2perror.c --- print SANA-II error message
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      : Sat Mar 20 02:10:14 1993 ppessi
  12.  * Last modified: Thu Mar 24 07:19:51 1994 ppessi
  13.  */
  14.  
  15. #ifdef KERNEL
  16. /*
  17.  * Note: This file is to be recompiled with AmiTCP/IP proper
  18.  *       with preprocessor symbol KERNEL defined.
  19.  *       You should NOT link it directly from "net.lib"! 
  20.  */
  21. #include <conf.h>
  22. #include <sys/param.h>
  23. #include <sys/systm.h>
  24. #include <sys/syslog.h>
  25. #define fprintf log
  26. #define stderr LOG_ERR
  27. #else
  28. #include <stdio.h>
  29. #endif
  30.  
  31. #include <devices/sana2.h>
  32. #include <net/sana2errno.h>
  33.  
  34. /****** sana2.lib/sana2perror *************************************************
  35.  
  36.     NAME
  37.     sana2perror - print SANA-II device error messages
  38.  
  39.     SYNOPSIS
  40.     #include <devices/sana2.h>
  41.  
  42.     sana2perror(banner, ios2request)
  43.  
  44.     void sana2perror(const char *, struct IOSana2Req *)
  45.  
  46.     FUNCTION
  47.     The sana2perror() function finds the error message corresponding to
  48.     the error in the given SANA-II IO request and writes it, followed by a
  49.     newline, to the stderr.  If the argument string is non-NULL it is
  50.     preappended to the message string and separated from it by a colon and
  51.     space (`: ').  If string is NULL only the error message string is
  52.     printed.
  53.  
  54.     NOTES
  55.     The sana2perror() function requires the stdio functions to be linked.
  56.  
  57.     SEE ALSO
  58.     Sana2PrintFault()
  59.  
  60. *******************************************************************************
  61. */
  62.  
  63. void 
  64. sana2perror(const char *banner, struct IOSana2Req *ios2)
  65. {
  66.   register WORD err = ios2->ios2_Req.io_Error;
  67.   register ULONG werr = ios2->ios2_WireError;
  68.   const char *errstr;
  69.  
  70.   if (err >= sana2io_nerr || -err > io_nerr) {
  71.     errstr = io_errlist[0];
  72.   } else { 
  73.     if (err < 0) 
  74.       /* Negative error codes are common with all IO devices */
  75.       errstr = io_errlist[-err];
  76.     else 
  77.       /* Positive error codes are SANA-II specific */ 
  78.       errstr = sana2io_errlist[err];
  79.   }
  80.  
  81.   if (werr == 0 || werr >= sana2wire_nerr) {
  82.     if (banner != NULL)
  83.       fprintf(stderr, "%s: %s\n", banner, errstr);
  84.     else
  85.       fprintf(stderr, "%s\n", errstr);
  86.   } else {
  87.     if (banner != NULL)
  88.       fprintf(stderr, "%s: %s (%s)\n", banner, errstr, sana2wire_errlist[werr]);
  89.     else
  90.       fprintf(stderr, "%s (%s)\n", errstr, sana2wire_errlist[werr]);
  91.   }
  92. }
  93.  
  94.